import { getInfo, setInfo } from '@/utils/storage'

export default {
  namespaced: true,
  state: {
    userInfo: getInfo()
  },
  mutations: {
    setUserInfo (state, obj) {
      state.userInfo = obj
      setInfo(obj)
    }
  },
  getters: {
    user: state => state.user
  },
  actions: {
    logout (context) {
      context.commit('setUserInfo', {})
      // 从user模块 访问其他模块的mutation，从根级别开始
      context.commit('cart/setCartList', [], { root: true })
    }
  }
}
